package model;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class HocSinh {
	private int maSo;
	private String hoTen;
	private float diemTrungBinh;
	
	//nhap thong tin
	public void nhapThongTin(int ms, String ht, float dtb) {
		this.setMaSo(ms);
		this.setHoTen(ht);
		this.setDiemTrungBinh(dtb);
	}
	
	//ghi thong tin ra file va xuat ra man hinh
	public void xuatThongTinRaFile() {
		DataOutputStream dos;
		
		try {
			FileOutputStream fos = new FileOutputStream("hocsinh.txt");
			dos = new DataOutputStream(fos);
			
			dos.writeInt(maSo);
			dos.writeUTF(hoTen);
			dos.writeFloat(diemTrungBinh);
			
		}
		catch (Exception e) {
			System.out.print("Khong the ghi file");
		}
	}
	
	//doc thong tin tu file
	public void docThongTinTuFile(String file) {
		DataInputStream dis;
		
		try {
			FileInputStream fis = new FileInputStream(file);
			dis = new DataInputStream(fis);
			
			maSo = dis.readInt();
			hoTen = dis.readUTF();
			diemTrungBinh = dis.readFloat();
		}
		catch (Exception e) {
			System.out.print("Khong the doc file!");
		}
	}
	
	public int getMaSo() {
		return maSo;
	}
	public void setMaSo(int maSo) {
		this.maSo = maSo;
	}
	public String getHoTen() {
		return hoTen;
	}
	public void setHoTen(String hoTen) {
		this.hoTen = hoTen;
	}
	public float getDiemTrungBinh() {
		return diemTrungBinh;
	}
	public void setDiemTrungBinh(float diemTrungBinh) {
		this.diemTrungBinh = diemTrungBinh;
	}
	
}
